package com.ruoyi.web.controller.tool;

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.EnvironmentPBEConfig;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

public class JasyptUtil {

    private final static String SECRECT = "1234qwer"; //秘钥
    private final static String ALGORITHM = "PBEWithMD5AndDES"; //加密算法

    private static String encrypt(String text){
        StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
        EnvironmentPBEConfig config = new EnvironmentPBEConfig();
        config.setAlgorithm(ALGORITHM);
        config.setPassword(SECRECT);
        standardPBEStringEncryptor.setConfig(config);
        return standardPBEStringEncryptor.encrypt(text);
    }

    public static String decrypt(String text) {
        StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
        EnvironmentPBEConfig config = new EnvironmentPBEConfig();
        config.setAlgorithm(ALGORITHM);
        config.setPassword(SECRECT);
        standardPBEStringEncryptor.setConfig(config);
        return standardPBEStringEncryptor.decrypt(text);
    }
    public static void main(String[] args) throws Exception {
        JasyptUtil jasyptUtil = new JasyptUtil();
        System.out.println("encrypt:"+jasyptUtil.encrypt("root"));
        System.out.println("decrypt:"+jasyptUtil.decrypt("5Wn63r/kW/BWxJHvOo2mrQ=="));
        System.out.println("encrypt:"+jasyptUtil.encrypt("password01!"));
        System.out.println("decrypt:"+jasyptUtil.decrypt("NklSEbwlVuWoBH15BlvsI1+65ikThi9r"));
        System.out.println("encrypt:"+jasyptUtil.encrypt("sjyf"));
        System.out.println("decrypt:"+jasyptUtil.decrypt("MtKffisL5/VyUMbcofOGuQ=="));
        System.out.println("encrypt:"+jasyptUtil.encrypt("Abc123!@#"));
        System.out.println("decrypt:"+jasyptUtil.decrypt("SX5RPzLkLPTv6Ixqg4wyQX78L4iCJMsg"));
        System.out.println("encrypt:"+jasyptUtil.encrypt("ODM"));
        System.out.println("decrypt:"+jasyptUtil.decrypt("WOYzjY7/luVltfmY50aDvQ=="));
        System.out.println("encrypt:"+jasyptUtil.encrypt("GXbc2021!#"));
        System.out.println("decrypt:"+jasyptUtil.decrypt("mxtbWuFOB3lnDsGWqsG8qRTQdbuohQJX"));
    }
}
